package com.market.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.market.dao.RoleDao;
import com.market.domain.Role;
import com.market.domain.User;
import com.market.manager.RoleManager;

@Service("roleManager")
public class RoleManagerImpl extends GenericManagerImpl<RoleDao, Role, Long>
		implements RoleManager {

	@Autowired
	public void setDao(RoleDao roleDao) {
		this.dao = roleDao;
	}

	public Role fetchOne(Role role) {
		if (role != null && role.getIsNew() == false) {
			return this.fetchOne(role.getId());
		} else {
			return role;
		}
	}
	
	

	@Override
	public Role fetchOne(Long id) {
		Role role = super.fetchOne(id);
		role.setUsers(this.fetchUsers(role));
		return role;
	}

	public List<User> fetchUsers(Role role) {
		return this.dao.findUsers(role);
	}

}
